package com.nut.lmsc.api.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nut.lmsc.api.req.BannerQueryReq;
import com.nut.lmsc.common.Result;
import com.nut.lmsc.entity.Banner;
import com.nut.lmsc.service.BannerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@Slf4j
@RestController
@RequestMapping("/admin/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @GetMapping("/list")
    public Result<IPage<Banner>> listPage(BannerQueryReq req) {
        return bannerService.listPage(req);
    }

    @GetMapping(value = "/{id}")
    public Result<Banner> detail(@PathVariable Integer id) {
        return bannerService.getById(id);
    }

    @PostMapping
    public Result add(@RequestBody Banner banner) {
        return bannerService.add(banner);
    }

    @PutMapping
    public Result update(@RequestBody Banner banner) {
        return bannerService.updateById(banner);
    }

    @DeleteMapping
    public Result delete(@RequestBody Set<Integer> ids) {
        return bannerService.deleteByIds(ids);
    }

}